<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>回忆 | 小糯米一周岁生日</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    
    <!-- 配置Tailwind -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#FF6B9B',
                        secondary: '#6BCBFF',
                        accent: '#FFD66B',
                        dark: '#1A1A2E'
                    },
                    fontFamily: {
                        cute: ['"Comic Sans MS"', '"Bubblegum Sans"', 'cursive'],
                    }
                }
            }
        }
    </script>
    
    <style type="text/tailwindcss">
        @layer utilities {
            .text-shadow {
                text-shadow: 0 2px 10px rgba(0,0,0,0.5);
            }
            .cinema-border {
                box-shadow: 0 0 0 8px #000, 0 0 0 10px #e50914, 0 0 0 20px #000;
            }
            .popcorn {
                position: absolute;
                background-color: #f5f5dc;
                border-radius: 50% 50% 30% 30%;
                opacity: 0;
            }
            .ticket {
                transition: all 0.3s ease;
                cursor: pointer;
            }
            .ticket:hover {
                transform: translateY(-10px) scale(1.02);
            }
            .ticket.active {
                border-color: #FF6B9B;
                background-color: rgba(255, 107, 155, 0.1);
            }
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0) rotate(0deg); }
            50% { transform: translateY(-15px) rotate(5deg); }
        }
        
        @keyframes popcorn-fall {
            0% {
                transform: translateY(-10vh) rotate(0deg);
                opacity: 1;
            }
            100% {
                transform: translateY(110vh) rotate(360deg);
                opacity: 0;
            }
        }
        
        @keyframes spotlight {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }
    </style>
</head>
<body class="bg-dark text-white min-h-screen font-cute overflow-x-hidden relative">
    <!-- 背景音乐 -->
    <audio id="background-music" loop>
        <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
    </audio>
    <audio id="pop-sound">
        <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3" type="audio/mpeg">
    </audio>
    <audio id="applause-sound">
        <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-5.mp3" type="audio/mpeg">
    </audio>
    
    <!-- 爆米花容器 -->
    <div id="popcorn-container" class="fixed inset-0 pointer-events-none z-10"></div>
    
    <!-- 聚光灯效果 -->
    <div class="fixed top-0 left-1/2 w-[80vw] h-[80vh] bg-white/5 rounded-full blur-3xl transform -translate-x-1/2 -translate-y-1/4 animate-spotlight pointer-events-none z-5"></div>
    
    <!-- 主内容 -->
    <div class="container mx-auto px-4 py-8 relative z-20">
        <!-- 导航 -->
        <nav class="flex justify-between items-center mb-10">
            <a href="welcome.html" class="text-white hover:text-primary transition-colors flex items-center">
                <i class="fa fa-arrow-left mr-2"></i> 返回
            </a>
            <h1 class="text-2xl md:text-3xl font-bold text-primary">成长回忆</h1>
            <a href="invitation.html" class="text-white hover:text-primary transition-colors flex items-center">
                下一页 <i class="fa fa-arrow-right ml-2"></i>
            </a>
        </nav>
        
        <!-- 电影院标题 -->
        <div class="text-center mb-10">
            <h2 class="text-[clamp(1.5rem,5vw,3rem)] font-bold text-white text-shadow mb-4">小糯米影院</h2>
            <p class="text-gray-300 max-w-2xl mx-auto">观看宝贝成长的精彩瞬间</p>
        </div>
        
        <!-- 视频播放区 -->
        <div class="relative max-w-5xl mx-auto mb-16">
            <div class="aspect-video cinema-border rounded-lg overflow-hidden relative">
                <!-- 视频播放器 -->
                <video id="main-video" class="w-full h-full object-cover" autoplay muted loop playsinline>
                    <source id="video-source" src="" type="video/mp4">
                    您的浏览器不支持视频播放
                </video>
                
                <!-- 播放控制 -->
                <div id="video-controls" class="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/80 to-transparent p-4 opacity-0 hover:opacity-100 transition-opacity">
                    <div class="flex items-center justify-between">
                        <button id="play-pause-btn" class="text-white text-xl hover:text-primary transition-colors">
                            <i class="fa fa-pause"></i>
                        </button>
                        <div class="text-sm text-gray-200">
                            <span id="current-time">0:00</span> / <span id="total-time">0:00</span>
                        </div>
                    </div>
                    
                    <!-- 进度条 -->
                    <div class="mt-2 h-1 bg-gray-600 rounded-full overflow-hidden">
                        <div id="progress-bar" class="h-full bg-primary w-0 transition-all"></div>
                    </div>
                </div>
            </div>
            
            <!-- 电影标题 -->
            <div class="text-center mt-6">
                <h3 id="video-title" class="text-2xl font-bold text-white"></h3>
                <p id="video-description" class="text-gray-300 mt-2"></p>
            </div>
        </div>
        
        <!-- 视频选择（电影票） -->
        <div class="mb-16">
            <h3 class="text-2xl font-bold text-center text-white mb-8">选择影片</h3>
            
            <div id="video-tickets" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 max-w-5xl mx-auto">
                <!-- 电影票将通过JS动态生成 -->
            </div>
        </div>
        
        <!-- 观影提示 -->
        <div class="max-w-2xl mx-auto bg-black/50 rounded-xl p-6 border border-gray-700">
            <h4 class="text-xl font-bold text-primary mb-4 flex items-center">
                <i class="fa fa-info-circle mr-2"></i> 观影提示
            </h4>
            <ul class="text-gray-300 space-y-2">
                <li class="flex items-start">
                    <i class="fa fa-check-circle text-secondary mt-1 mr-2"></i>
                    <span>点击不同的"电影票"可以切换观看不同的视频</span>
                </li>
                <li class="flex items-start">
                    <i class="fa fa-check-circle text-secondary mt-1 mr-2"></i>
                    <span>视频播放完毕后会自动播放下一个</span>
                </li>
                <li class="flex items-start">
                    <i class="fa fa-check-circle text-secondary mt-1 mr-2"></i>
                    <span>点击视频区域可以显示/隐藏播放控制</span>
                </li>
                <li class="flex items-start">
                    <i class="fa fa-check-circle text-secondary mt-1 mr-2"></i>
                    <span>祝您观影愉快，分享小糯米的成长喜悦</span>
                </li>
            </ul>
        </div>
    </div>
    
    <script>
        // 视频数据
        let videosData = null;
        let currentVideoIndex = 0;
        let isPlaying = true;
        
        // DOM加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 加载视频数据
            fetch('data/content.json')
                .then(response => {
                    if (!response.ok) throw new Error('数据加载失败');
                    return response.json();
                })
                .then(data => {
                    videosData = data.videos;
                    
                    // 初始化页面
                    initPage();
                })
                .catch(error => {
                    console.error('初始化失败:', error);
                    alert('页面加载失败，请刷新重试');
                });
            
            // 播放背景音乐
            const music = document.getElementById('background-music');
            music.volume = 0.2;
            music.play().catch(e => {
                console.log('需要用户交互才能播放音乐:', e);
                document.addEventListener('click', () => {
                    music.play();
                }, { once: true });
            });
        });
        
        // 初始化页面
        function initPage() {
            // 创建电影票
            createVideoTickets();
            
            // 加载第一个视频
            loadVideo(0);
            
            // 初始化视频控制
            initVideoControls();
            
            // 开始生成爆米花效果
            startPopcornEffect();
        }
        
        // 创建视频票
        function createVideoTickets() {
            const container = document.getElementById('video-tickets');
            
            videosData.forEach((video, index) => {
                const ticket = document.createElement('div');
                ticket.className = `ticket ${index === 0 ? 'active' : ''} bg-black/30 border-2 rounded-xl p-5 flex flex-col`;
                ticket.dataset.index = index;
                
                ticket.innerHTML = `
                    <div class="flex justify-between items-start mb-4">
                        <span class="bg-primary text-white text-xs px-2 py-1 rounded">影片 ${index + 1}</span>
                        <span class="text-accent"><i class="fa fa-ticket"></i></span>
                    </div>
                    <h4 class="text-xl font-bold text-white mb-2">${video.title}</h4>
                    <p class="text-gray-400 text-sm mb-4 flex-grow">${video.description}</p>
                    <div class="text-xs text-gray-500">
                        <span><i class="fa fa-clock-o mr-1"></i> ${video.duration}</span>
                    </div>
                `;
                
                // 点击切换视频
                ticket.addEventListener('click', () => {
                    // 更新活跃状态
                    document.querySelectorAll('.ticket').forEach(t => t.classList.remove('active'));
                    ticket.classList.add('active');
                    
                    // 加载视频
                    loadVideo(index);
                    
                    // 播放音效
                    document.getElementById('pop-sound').play();
                });
                
                container.appendChild(ticket);
            });
        }
        
        // 加载视频
        function loadVideo(index) {
            currentVideoIndex = index;
            const video = videosData[index];
            
            // 更新视频源
            const videoElement = document.getElementById('main-video');
            const sourceElement = document.getElementById('video-source');
            sourceElement.src = video.url;
            videoElement.load();
            
            // 如果之前是播放状态，继续播放
            if (isPlaying) {
                videoElement.play();
            }
            
            // 更新视频信息
            document.getElementById('video-title').textContent = video.title;
            document.getElementById('video-description').textContent = video.description;
        }
        
        // 初始化视频控制
        function initVideoControls() {
            const videoElement = document.getElementById('main-video');
            const controls = document.getElementById('video-controls');
            const playPauseBtn = document.getElementById('play-pause-btn');
            const progressBar = document.getElementById('progress-bar');
            const currentTimeEl = document.getElementById('current-time');
            const totalTimeEl = document.getElementById('total-time');
            
            // 显示控制
            videoElement.addEventListener('mouseover', () => {
                controls.style.opacity = '1';
            });
            
            // 隐藏控制
            setTimeout(() => {
                controls.style.opacity = '0';
            }, 3000);
            
            controls.addEventListener('mouseleave', () => {
                if (!videoElement.paused) {
                    setTimeout(() => {
                        controls.style.opacity = '0';
                    }, 3000);
                }
            });
            
            // 播放/暂停
            playPauseBtn.addEventListener('click', togglePlayPause);
            
            videoElement.addEventListener('click', togglePlayPause);
            
            // 更新进度
            videoElement.addEventListener('timeupdate', () => {
                const percent = (videoElement.currentTime / videoElement.duration) * 100;
                progressBar.style.width = `${percent}%`;
                
                // 更新时间显示
                currentTimeEl.textContent = formatTime(videoElement.currentTime);
                if (videoElement.duration) {
                    totalTimeEl.textContent = formatTime(videoElement.duration);
                }
            });
            
            // 视频结束时自动播放下一个
            videoElement.addEventListener('ended', () => {
                // 播放掌声
                document.getElementById('applause-sound').play();
                
                // 延迟后播放下一个视频
                setTimeout(() => {
                    const nextIndex = (currentVideoIndex + 1) % videosData.length;
                    
                    // 更新电影票状态
                    document.querySelectorAll('.ticket').forEach(t => t.classList.remove('active'));
                    document.querySelectorAll('.ticket')[nextIndex].classList.add('active');
                    
                    // 播放下一个视频
                    loadVideo(nextIndex);
                }, 2000);
            });
            
            // 点击进度条跳转
            controls.addEventListener('click', (e) => {
                if (e.target === progressBar || e.target.parentElement === progressBar.parentElement) {
                    const rect = progressBar.parentElement.getBoundingClientRect();
                    const pos = (e.clientX - rect.left) / rect.width;
                    videoElement.currentTime = pos * videoElement.duration;
                }
            });
        }
        
        // 切换播放/暂停
        function togglePlayPause() {
            const videoElement = document.getElementById('main-video');
            const playPauseBtn = document.getElementById('play-pause-btn');
            
            if (videoElement.paused) {
                videoElement.play();
                playPauseBtn.innerHTML = '<i class="fa fa-pause"></i>';
                isPlaying = true;
            } else {
                videoElement.pause();
                playPauseBtn.innerHTML = '<i class="fa fa-play"></i>';
                isPlaying = false;
            }
        }
        
        // 格式化时间
        function formatTime(seconds) {
            const minutes = Math.floor(seconds / 60);
            const remainingSeconds = Math.floor(seconds % 60);
            return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
        }
        
        // 爆米花效果
        function startPopcornEffect() {
            function createPopcorn() {
                const container = document.getElementById('popcorn-container');
                const count = Math.floor(Math.random() * 5) + 3;
                
                for (let i = 0; i < count; i++) {
                    const popcorn = document.createElement('div');
                    popcorn.className = 'popcorn';
                    
                    // 随机大小
                    const size = Math.random() * 10 + 5;
                    popcorn.style.width = `${size}px`;
                    popcorn.style.height = `${size}px`;
                    
                    // 随机位置（左侧或右侧）
                    const side = Math.random() > 0.5 ? 'left' : 'right';
                    const pos = Math.random() * 30 + 10; // 10% - 40%
                    popcorn.style[side] = `${pos}%`;
                    
                    // 随机动画
                    const duration = Math.random() * 8 + 4;
                    const delay = Math.random() * 5;
                    popcorn.style.animation = `popcorn-fall ${duration}s linear forwards ${delay}s`;
                    
                    container.appendChild(popcorn);
                    
                    // 动画结束后移除
                    setTimeout(() => {
                        if (container.contains(popcorn)) {
                            container.removeChild(popcorn);
                        }
                    }, (duration + delay) * 1000);
                }
            }
            
            // 初始创建
            createPopcorn();
            
            // 定时创建
            setInterval(createPopcorn, 3000);
        }
    </script>
</body>
</html>
